#include <bits/stdc++.h>

#define in read<int>()
#define lin read<ll>()
#define fi first
#define se second
#define pii pair<ll,int>
#define pb push_back
#define vec vector<int>
#define y1 y_____hahahaha_____1

using namespace std;

typedef long long ll;

template <typename T>
T read(){T x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); return x * sgn;}

const int N = 2.5e5 + 10;
const ll inf = 1e18;

int n,m,Q,tms;
struct Queryy{int op,l,r,c;ll k;}q[N];
int ans[N];

namespace BIT{
	ll tr[N];
	void add(int x,ll y){for(;x <= n;x += x & -x) tr[x] += y;}
	ll query(int x,ll y = 0){for(;x;x -= x & -x) y += tr[x];return y;}
}

namespace seg1{
	ll x[N<<2],y[N<<2];
	void add(int o,ll p,ll q){x[o] += p; y[o] = max(y[o] + p,q);}
	void pushdown(int o){if(x[o] || y[o]) add(o << 1,x[o],y[o]),add(o << 1 | 1,x[o],y[o]),x[o] = y[o] = 0;}
	void upd(int xl,int xr,ll v,int o = 1,int l = 1,int r = n){
		if(l == xl && r == xr) return add(o,v,0); int mid = l + r >> 1; pushdown(o); if(xr <= mid) upd(xl,xr,v,o << 1,l,mid);else if(xl > mid) upd(xl,xr,v,o<<1|1,mid+1,r); else upd(xl,mid,v,o<<1,l,mid),upd(mid+1,xr,v,o<<1|1,mid+1,r);
	}
	ll query(int pos,int o = 1,int l = 1,int r = n){
		if(l == r) return max(x[o],y[o]); int mid = l + r >> 1; pushdown(o); if(pos <= mid) return query(pos,o << 1,l,mid); return query(pos,o<<1|1,mid+1,r);
	}
}

namespace seg2{
	ll mn[N<<2],lz[N<<2];vector<pii> pot[N];int st[N],L[N<<2],R[N<<2],mid[N<<2];
	inline void add(int o,ll v){lz[o] += v; mn[o] += v;}
	inline void pushdown(int o){if(lz[o]) add(o << 1,lz[o]),add(o << 1 | 1,lz[o]),lz[o] = 0;}
	void build(int o = 1,int l = 1,int r = n){
		L[o] = l;R[o] = r;if(l == r){st[l] = 0; mn[o] = pot[l].size() > 0? pot[l][0].fi : inf;return;} mid[o] = l + r >> 1; build(o<<1,l,mid[o]),build(o<<1|1,mid[o]+1,r); mn[o] = min(mn[o << 1],mn[o << 1 | 1]);
	}
	void upd(int xl,int xr,ll v,int o = 1){
		if(xl <= L[o] && xr >= R[o]) return add(o,v); pushdown(o); if(xr <= mid[o]) upd(xl,xr,v,o<<1); else if(xl > mid[o]) upd(xl,xr,v,o<<1|1);else upd(xl,mid[o],v,o<<1),upd(mid[o]+1,xr,v,o<<1|1); mn[o] = min(mn[o << 1],mn[o << 1 | 1]);
	}
	void calc(int col,int o = 1){
		if(mn[o] > 0) return; if(L[o] == R[o]){int l = L[o]; while(st[l] < (int) pot[l].size() && mn[o] <= 0){ans[pot[l][st[l]].se] = col; if(st[l] + 1 == (int)pot[l].size()) mn[o] = inf;else mn[o] += pot[l][st[l]+1].fi - pot[L[o]][st[l]].fi,st[l]++;}return;} pushdown(o); calc(col,o << 1); calc(col,o<<1|1); mn[o] = min(mn[o << 1],mn[o<<1|1]);
	}
}

using seg2 :: pot;

int main(){
#ifndef ONLINE_JUDGE
	freopen("03-13.in","r",stdin); freopen("P7560.out","w",stdout);
#endif
	n = in,m = in,Q = in;
	for(int i = 1;i <= Q;i++){
		q[i].op = in;q[i].l = in;
		if(q[i].op == 1) q[i].r = in,q[i].c = in,q[i].k = lin,seg1::upd(q[i].l,q[i].r,q[i].k),BIT::add(q[i].l,q[i].k),BIT::add(q[i].r + 1,-q[i].k);
		else if(q[i].op == 2) q[i].r = in,q[i].k = lin,seg1::upd(q[i].l,q[i].r,-q[i].k);
		else{
			q[i].k = lin; ++tms; ll res = seg1::query(q[i].l); if(res >= q[i].k){res = BIT::query(q[i].l) - res + q[i].k; pot[q[i].l].pb(pii(res,tms));}
		}
	}
	for(int i = 1;i <= n;i++) sort(pot[i].begin(),pot[i].end());
	seg2::build();cerr<<"!"<<endl;
	for(int i = 1;i <= Q;i++)
		if(q[i].op == 1){
			seg2::upd(q[i].l,q[i].r,-q[i].k); seg2::calc(q[i].c);
		}
	for(int i = 1;i <= tms;i++) printf("%d\n",ans[i]);
	return 0;
}
